package 每日一题;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @author chenhong
 * @version 1.0
 * @description TODO
 * @date 2023/5/2 11:53
 */
public class L970 {

    public List<Integer> powerfulIntegers(int x, int y, int bound) {
        List<Integer> ans = new ArrayList<>();
        List<Integer> xl = new ArrayList<>();
        List<Integer> yl = new ArrayList<>();
        int k = 1;
        while (k <= bound) {
            xl.add(k);
            if(x == 1)
                break;
            k *= x;
        }

        k = 1;
        while (k <= bound) {
            yl.add(k);
            if(y == 1)
                break;
            k *= y;
        }
        for (int i = 0; i < xl.size(); i++) {
            for (int j = 0; j < yl.size(); j++) {
                if (xl.get(i) + yl.get(j) <= bound) {
                    if (!ans.contains(xl.get(i) + yl.get(j))) {
                        ans.add(xl.get(i) + yl.get(j));
                    }
                }
            }
        }
        Collections.sort(ans);
        return ans;
    }
}
